package com.example.mydemo1.controller;

import com.example.mydemo1.entity.common.PageParams;
import com.example.mydemo1.entity.common.PageResult;
import com.example.mydemo1.entity.common.AppResp;
import com.example.mydemo1.entity.vo.SysRoleVO;
import com.example.mydemo1.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 角色表 控制层
 * </p>
 *
 * @createTime: 2023/09/16 14:29:44
 */
@Validated
@RestController("sysRoleController4mydemo1")
@RequestMapping("/api/v1/test/sys-role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @PostMapping("/page")
    public AppResp<PageResult<SysRoleVO>> page(@RequestBody PageParams<SysRoleVO> pageParams){
        return sysRoleService.page(pageParams);
    }

    @GetMapping("")
    public AppResp<SysRoleVO> queryById(@RequestParam(name = "id") String sysRoleId){
        return sysRoleService.queryById(sysRoleId);
    }

    @PostMapping("")
    public AppResp<Void> add(@Validated @RequestBody SysRoleVO sysRoleVO){
        return sysRoleService.add(sysRoleVO);
    }

    @DeleteMapping("")
    public AppResp<Void> delById(@RequestParam(name = "id") String sysRoleId){
        return sysRoleService.delById(sysRoleId);
    }

    @PutMapping("")
    public AppResp<Void> modify(@Validated @RequestBody SysRoleVO sysRoleVO){
        return sysRoleService.modify(sysRoleVO);
    }

    @PostMapping("/batch-insert")
    public AppResp<Void> batchInsert(@RequestBody List<SysRoleVO> sysRoleVos) {
        return sysRoleService.batchAdd(sysRoleVos);
    }

    @PostMapping("/batch-update")
    public AppResp<Void> batchUpdate(@RequestBody List<SysRoleVO> sysRoleVos) {
        return sysRoleService.batchModify(sysRoleVos);
    }

    @PostMapping("/batch-delete")
    public AppResp<Void> batchDelete(@RequestBody List<SysRoleVO> sysRoleVos) {
        return sysRoleService.batchDelete(sysRoleVos);
    }
}